<template>
  <div>
    <div>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{path:'/'}">首页</el-breadcrumb-item>
        <el-breadcrumb-item >投诉列表页</el-breadcrumb-item>
      </el-breadcrumb>
      <el-button style="position: absolute;right: 0;top:0;color:#fff;background-color: #1dd0b7;" @click="goComplaint">去投诉</el-button>
    </div>
    <el-table v-loading="loading" :data="listData" :header-cell-style="{background:'#F6FDFD',color:'#000',height:'46px'}"
        :row-style="{height:'50px'}" @row-click="handleTableRow" style="margin-top: 40px;">
      <el-table-column type="index" label="序号" width="244"></el-table-column>
      <el-table-column prop="title" label="投诉名称" width="530"></el-table-column>
      <el-table-column prop="createTime" label="创建时间" width="300">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="处理状态" align="left" prop="status">
        <template slot-scope="scope">
          <span v-if="scope.row.status=== '0'" style="color: #E4931B;">
          {{ getStatusValue(scope.row.status) }}
          </span>
          <template v-else>
            {{ getStatusValue(scope.row.status) }}
          </template>
        </template>
      </el-table-column>
      <el-table-column prop="index" label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="mini" style="color: #1dd0b7;" >查看</el-button> 
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getData"
    />
    <el-dialog title="投诉" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" label-width="80px" :rules="rules">
        <el-form-item label="投诉标题" prop="title">
          <el-input v-model="form.title" placeholder="请输入投诉标题"/>
        </el-form-item>
        <el-form-item label="投诉信息" prop="content">
          <editor v-model="form.content" :min-height="192" :height="400"/>
        </el-form-item>
        <el-form-item label="联系人" prop="contact">
          <el-input v-model="form.contact" placeholder="请输入联系人"/>
        </el-form-item>
        <el-form-item label="联系电话" prop="contactTel">
          <el-input v-model="form.contactTel" placeholder="请输入联系电话"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listComplaint, addComplaint} from '@/api/bid/complaint'
import Editor from '@/components/MyEditor'
import {mapGetters} from "vuex";
export default {
  name: "list",
  components: {
    Editor
  },
  data() {
    return {
     loading:true,
     listData:[],
     queryParams:{
      pageSize:20,
      pageNum:1
     },
     total:0,
     open: false,
     form: {},
     complaintStatus: [],
     rules:{
      title: [{
        required: true,
        message: "投诉标题不能为空",
      }],
      content: [{
        required: true,
        message: "投诉信息不能为空",
      }],
      contact: [{
        required: true,
        message: "联系人不能为空",
      }],
      contactTel: [{
        required: true,
        message: "联系电话不能为空",
      }],
     }
    }
  },
  created() {
    this.getData()
    this.getDicts('complaint_status').then(x => {
      this.complaintStatus = x.data
    })
  },
  methods: {
    goComplaint() {
      this.open = true
    },
    handleTableRow(row){
      this.$router.push(`/complaint/detail?id=${row.id}`)
    },
    getData(){
      listComplaint(this.queryParams).then(res=>{
        console.log(res);
        this.listData = res.rows
        this.total = res.total
        this.loading=false
      })
    },
    getStatusValue(key) {
      const dict = this.complaintStatus.filter(x => x.dictValue === key.toString())
      if (dict && dict.length > 0) {
        return dict[0].dictLabel
      }
      return ''
    },
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          this.form.enterpriseId = this.userId
          addComplaint(this.form).then(response => {
            this.msgSuccess('新增成功')
            this.open = false
            this.getData()
          })
        }
      })
    },
    cancel() {
      this.open = false
      this.form = {
        id: null,
        enterpriseId: null,
        title: null,
        content: null,
        contact: null,
        contactTel: null,
        status: '0',
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        enterpriseName: null
      }
    }
  },
  computed:{
    ...mapGetters(['userId'])
  }
}
</script>

<style lang="scss" scoped>
.list{
  .content{
    width: 80%;
    margin: 10px;
    padding: 30px;
    background-color: #fff;
  }
}

::v-deep .el-pagination{
  display: flex;
  justify-content: center;
  position: relative;
}

::v-deep .el-pager .active{
  color: #1dd0b7;
  cursor: pointer;
}
</style>
